<?php
/*
Example of using ImgCaptcha in the form.
Copyright (C) 2010  Adrian Michalski aka MicMic

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/
	session_start();
?>
<html>
	<head>
		<title>MicMic's ImgCaptcha Test</title>
		<style type="text/css">
		body{
		background: grey;
		color: black;
		font: 16px "Segoe UI", Verdana, sans-serif
		}
		td{
		padding: 5px
		}
		h1{
		text-shadow: 0.0em 0.0em 0.5em grey;
		}
		#main{
		width: 640px;
		margin: 20 auto;
		padding: 20px;
		background: white;
		text-align: center;
		}
		.hint{
		font-size: 12px;
		font-style: Italic;
		}
		</style>
	</head>

	<body>
		<div id="main">
		<h1>ImgCaptcha test</h1>
		<?php
		if (empty($_POST)) { ?>
		<form method="POST">
			<table>
			<tr><td>Username:</td><td><input type="text" name="user" /></tr>
			<tr><td>Password:</td><td><input type="text" name="password" /></tr>
			<tr><td><img id="imgcaptcha_image" src="imgcaptcha/imgcaptcha_show.php?sid=<?php echo md5(uniqid(time())); ?>"><br />
			<span class="hint"><a href="#" onclick="document.getElementById('imgcaptcha_image').src='imgcaptcha/imgcaptcha_show.php?sid=' + Math.random(); return false">Don't see anything? Click to reload image.</a></span></td>
			<td>What do you see on the image?<br /><span class="hint">Hint: word must be a noun in the singular!</span><br /><input type="text" name="code" /></td></tr>
			<tr><td><input type="reset" value="Clear" /></td><td><input type="submit" value="Register" /></td></tr>
		</table>
		
		</form>
		<?php
		}else{
			include("imgcaptcha/imgcaptcha.php");
			$img = new imgCaptcha();
			$valid = $img->checkCode($_POST['code']);

			if($valid == true) {
				echo "<center>Correct!</center>";
			} else {
				echo "<center>H@H@H@ Die, spambot! <a href=\"javascript:history.go(-1)\">Try again</a>?</center>";
			}
		}
		?>
		</div>
	</body>
</html>